import { appConfig } from '@/config'

export function setUser(data) {
  localStorage.setItem('user', JSON.stringify(data))
}

export function removeUser() {
  localStorage.removeItem('user')
}

export function getUser() {
  return localStorage.getItem('user')
    ? JSON.parse(localStorage.getItem('user'))
    : {}
}
export function getToken() {
  return getUser().token
}

export function getUserName() {
  return getUser().username
}

export function getUserType() {
  return getUser().type
}

export function getUserId() {
  return getUser().id
}
export function getUserRoles() {
  return appConfig.userType[getUserType()]
}

export function checkUserIsSuperMgrMarket() {
  return getUser().type === 0 && getUser.specialAdmin === 1
}

export function checkUserHasDefaultPwd() {
  return getUser().pwd === '770fb34b448d08f2ddfaf340332a5837'
}

export function setFormParams(key, data) {
  localStorage.setItem(key, JSON.stringify(data))
}
export function getFormParams(key) {
  return localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key)) : {}
}
